﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 父子类转换
{
    class Program
    {
        static void Main(string[] args)
        {
            Dog dog = new Dog();
            Animal animal = dog; //子类转换为父类  隐式转换

            Dog dog1 = animal as Dog; //成功

            Cat cat = animal as Cat;// 不能成功 返回为null

            Cat cat1 = (Cat)animal;//运行时报错

            //不管时as还是强转,只能转换为原来类型.
        }
    }

    class Animal
    {

    }

    class Cat:Animal
    {

    }

    class Dog:Animal
    {

    }
}
